import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class NotificationListenerWidget extends StatefulWidget {
  const NotificationListenerWidget({super.key});

  @override
  _NotificationListenerWidgetState createState() =>
      _NotificationListenerWidgetState();
}

class _NotificationListenerWidgetState extends State<NotificationListenerWidget> {
  static const EventChannel eventChannel = EventChannel('com.yichip.watch/notification_channel');
  String _lastNotification = 'No notification received yet';

  @override
  void initState() {
    super.initState();
    eventChannel.receiveBroadcastStream().listen((dynamic event) {
      setState(() {
        _lastNotification = event;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text('Last notification: $_lastNotification'),
    );
  }
}
